<?php

namespace App\Datas;

use App\Tools\Sql;
use Illuminate\Support\Facades\DB;

class Base
{
    public function updateFiledById($id,$updateFiled) {
        if (empty($updateFiled)) {
            return ;
        }
        DB::table($this->tableName)->where(["id" => $id])->update($updateFiled);
    }

    public function insert($newData) {
        DB::table($this->tableName)->insert($newData);
    }

    public function getOneInfoById($id,$selectFiled = ["*"]) {
        $info = DB::table($this->tableName)->where(["id" => $id])->first($selectFiled);
        if (!empty($info)) {
            return (array)$info;
        }
        return [];
    }

    public function getOneInfo($where,$selectFiled = ["*"]) {
        $info = DB::table($this->tableName)->where($where)->first($selectFiled);
        if (!empty($info)) {
            return (array)$info;
        }
        return [];
    }

    public function select($selectField, $where, $order = '', $start = 0, $num = 0, $forceMaster = false, $forceIndex = '') {
        $sql = Sql::select($this->tableName,$selectField,$where,$order,$start,$num,$forceMaster,$forceIndex);
        $list = DB::select($sql);
        foreach ($list as &$item) {
            $item = (array)$item;
        }
        return $list;
    }
}